import { defineConfig } from "vite";
import { resolve } from "path";
import vue from "@vitejs/plugin-vue";
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ArcoResolver } from "unplugin-vue-components/resolvers";
import { vitePluginForArco } from "@arco-plugins/vite-vue";
import libBuildConfig from "./build/buildLib.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// 定义一些常量以提高代码的可读性和易维护性
export const ROOT_PATH = __dirname;

export default defineConfig(({ mode }) => {
  if (mode === "lib") {
    return libBuildConfig;
  }
  return {
    plugins: [
      vue(),
      AutoImport({
        resolvers: [ArcoResolver()],
      }),
      Components({
        resolvers: [
          ArcoResolver({
            sideEffect: true,
          }),
        ],
      }),
      vitePluginForArco({
        style: "css",
      }),
    ],
    resolve: {
      alias: {
        "@": resolve(__dirname, "packages"),
      },
    },
    server: {
      port: 8020,
    },
  };
});
